<?php 
namespace Home\Controller;
use Think\Controller;
class JianliController extends Controller{
		public $Jl;
		public $Wx;
		public $Pexp;
		public $Edu;
		public $Opus;
		public function __construct(){
			parent::__construct();
			$this->Jl 	= D('Postresumes');
			$this->Wx 	= D('Workexp');
			$this->Pexp = D('Proexp');
			$this->Edu  = D('Eduexp');
			$this->Opus = D('Opus');
		}


		public function getId($uid){
			//权限检测:检测登陆并检测COOKIE是否正确
			if(cookie('Qkey')){
				if(!homechcekck()){
					$this->error('信息不正确,请重新登陆!','/',1);
					exit;
				}
			}else{
				$this->error('请登陆!','/Home/User/login',1);
			}

			//检测账号类型:Utype = 1为企业,0为求职者
			if (cookie('Utype') != 0 ) {
				$this->error('你是企业用户~去发布职位吧','/Home/company/create',1);
			}


			return $this->Jl->field('pid,uid')->where(['uid'=>cookie('sn')])->find();
			exit;
		}

		public function jianli(){
		
			// $is_onece = $this->Jl->field('pid,uid')->where('uid='.'1')->select();//判断是否第一次提交简历,如不是,则update
			// print_r($is_onece[0]['pid']);
			
			//权限检测:检测登陆并检测COOKIE是否正确
			if(cookie('Qkey')){
				if(!homechcekck()){
					$this->error('信息不正确,请重新登陆!','/',1);
					exit;
				}
			}else{
				$this->error('请登陆!','/Home/User/login',1);
			}

			//检测账号类型:Utype = 1为企业,0为求职者
			if (cookie('Utype') != 0 ) {
				$this->error('你是企业用户~去发布职位吧','/Home/company/create',1);
			}


			if (empty($_POST)) {
				$jl = $this->Jl->where(['uid'=>cookie('sn')])->find();
				// print_r($jl);
				$this->assign('jl',$jl);
				$this->display('User/jianli');
			}elseif(empty($this->getId())){				
				$this->Jl->uid 			= cookie('sn');
				$this->Jl->name 		= I('post.name');
				$this->Jl->gender 		= I('post.sex');
				$this->Jl->education 	= I('post.highestEducation');
				$this->Jl->job_life 	= I('post.workYear');
				$this->Jl->email 		= I('post.email');
				$this->Jl->tel			= I('post.phone');
				$this->Jl->job_status 	= I('post.status');
				if ($this->Jl->add()) {
					echo json_encode(['msg'=>'保存成功']);
				}
			}else{
				$this->Jl->find($this->getId()['pid']);
				$this->Jl->name 		= I('post.name');
				$this->Jl->gender 		= I('post.sex');
				$this->Jl->education 	= I('post.highestEducation');
				$this->Jl->job_life 	= I('post.workYear');
				$this->Jl->email 		= I('post.email');
				$this->Jl->tel			= I('post.phone');
				$this->Jl->job_status 	= I('post.status');
				if ($this->Jl->save()) {
					echo json_encode(['msg'=>'修改成功!']);
				}
			}
		}


		public function wish_job(){

			//权限检测:检测登陆并检测COOKIE是否正确
			if(cookie('Qkey')){
				if(!homechcekck()){
					$this->error('信息不正确,请重新登陆!','/',1);
					exit;
				}
			}else{
				$this->error('请登陆!','/Home/User/login',1);
			}

			//检测账号类型:Utype = 1为企业,0为求职者
			if (cookie('Utype') != 0 ) {
				$this->error('你是企业用户~去发布职位吧','/Home/company/create',1);
			}


			$this->Jl 				= D('Postresumes');
			$this->Jl->find($this->getId()['pid']);
			$this->Jl->wish_city   = I('post.city');
			$this->Jl->job_type 	= I('post.positionType'); 
			$this->Jl->job_name 	= I('post.positionName');
			$this->Jl->wish_pay  	= I('post.salarys');
			if ($this->Jl->save()) {
				
			}
		}

		public function job_jl(){
			//权限检测:检测登陆并检测COOKIE是否正确
			if(cookie('Qkey')){
				if(!homechcekck()){
					$this->error('信息不正确,请重新登陆!','/',1);
					exit;
				}
			}else{
				$this->error('请登陆!','/Home/User/login',1);
			}

			//检测账号类型:Utype = 1为企业,0为求职者
			if (cookie('Utype') != 0 ) {
				$this->error('你是企业用户~去发布职位吧','/Home/company/create',1);
			}

			$this->Wx->uid 			= $this->getId()['uid'];
			$this->Wx->pid 			= $this->getId()['pid'];
			$this->Wx->companyname 	= I('post.companyName');
			$this->Wx->cargo 		= I('post.positionName');
			$this->Wx->startyear 	= I('post.startYear');
			$this->Wx->startmonth 	= I('post.startMonth');
			$this->Wx->endyear 		= I('post.endYear');
			$this->Wx->endmonth 	= I('post.endMonth');
			if ($this->Wx->add()) {
				echo json_encode(['msg'=>'添加成功']);
			}

		}

		public function proexp(){
			//权限检测:检测登陆并检测COOKIE是否正确
			if(cookie('Qkey')){
				if(!homechcekck()){
					$this->error('信息不正确,请重新登陆!','/',1);
					exit;
				}
			}else{
				$this->error('请登陆!','/Home/User/login',1);
			}

			//检测账号类型:Utype = 1为企业,0为求职者
			if (cookie('Utype') != 0 ) {
				$this->error('你是企业用户~去发布职位吧','/Home/company/create',1);
			}

			
			$this->Pexp->uid 			= $this->getId()['uid'];
			$this->Pexp->pid 			= $this->getId()['pid'];
			$this->Pexp->xmmc 			= I('post.projectName');
			$this->Pexp->position 		= I('post.positionName');
			$this->Pexp->startyear 		= I('post.startYear');
			$this->Pexp->startmonth 	= I('post.startMonth');
			$this->Pexp->endyear 		= I('post.endYear');
			$this->Pexp->endmonth 		= I('post.endMonth');
			$this->Pexp->xmms 			= I('post.projectRemark');
			if ($this->Pexp->add()) {
				echo json_encode(['msg'=>'添加好啦']);
			}
		
		}

		public function edu(){
			//权限检测:检测登陆并检测COOKIE是否正确
			if(cookie('Qkey')){
				if(!homechcekck()){
					$this->error('信息不正确,请重新登陆!','/',1);
					exit;
				}
			}else{
				$this->error('请登陆!','/Home/User/login',1);
			}

			//检测账号类型:Utype = 1为企业,0为求职者
			if (cookie('Utype') != 0 ) {
				$this->error('你是企业用户~去发布职位吧','/Home/company/create',1);
			}

				$this->Edu->uid 			= $this->getId()['uid'];
				$this->Edu->pid 			= $this->getId()['pid'];
				$this->Edu->school 			= I('post.schoolName');
				$this->Edu->edulv 			= I('post.education');
				$this->Edu->excuname 		= I('post.professional');
				$this->Edu->startyear 		= I('post.startYear');
				$this->Edu->endyear 		= I('post.endYear');
				if ($this->Edu->add()) {
					echo json_encode(['msg'=>'教育信息更新成功']);
				}
		}

		public function introduce(){
			//权限检测:检测登陆并检测COOKIE是否正确
			if(cookie('Qkey')){
				if(!homechcekck()){
					$this->error('信息不正确,请重新登陆!','/',1);
					exit;
				}
			}else{
				$this->error('请登陆!','/Home/User/login',1);
			}

			//检测账号类型:Utype = 1为企业,0为求职者
			if (cookie('Utype') != 0 ) {
				$this->error('你是企业用户~去发布职位吧','/Home/company/create',1);
			}


			$this->Jl->find($this->getId()['pid']);
			$this->Jl->self_introduce 	= I('post.myRemark');
			if($this->Jl->save()){
				echo json_encode(['msg'=>'自我介绍更新成功']);
			}

		}

		public function opus(){
			//权限检测:检测登陆并检测COOKIE是否正确
			if(cookie('Qkey')){
				if(!homechcekck()){
					$this->error('信息不正确,请重新登陆!','/',1);
					exit;
				}
			}else{
				$this->error('请登陆!','/Home/User/login',1);
			}

			//检测账号类型:Utype = 1为企业,0为求职者
			if (cookie('Utype') != 0 ) {
				$this->error('你是企业用户~去发布职位吧','/Home/company/create',1);
			}

			$this->Opus->pid 	= $this->getId()['pid'];
			$this->Opus->uid 	= $this->getId()['uid'];
			$this->Opus->pro_link 	= I('post.url');
			$this->Opus->pro_prointro = I('post.workName');
			if ($this->Opus->add()) {
				echo json_encode(['msg'=>'作品添加完毕']);
			}

		}

		public function prev(){
			//权限检测:检测登陆并检测COOKIE是否正确
			if(cookie('Qkey')){
				if(!homechcekck()){
					$this->error('信息不正确,请重新登陆!','/',1);
					exit;
				}
			}else{
				$this->error('请登陆!','/Home/User/login',1);
			}

			//检测账号类型:Utype = 1为企业,0为求职者
			if (cookie('Utype') != 0 ) {
				$this->error('你是企业用户~去发布职位吧','/Home/company/create',1);
			}

			
		// public $Jl;
		// public $Wx;
		// public $Pexp;
		// public $Edu;
		// public $Opus;
			$base 		= $this->Jl->where(['uid'=>$this->getid()['uid']])->find();
			$workexp 	= $this->Wx->where(['pid'=>$base['pid']])->select();
			$pexp 		= $this->Pexp->where(['pid'=>$base['pid']])->select();
			$edu 		= $this->Edu->where(['pid'=>$base['pid']])->select();
			$opus 		= $this->Opus->where(['pid'=>$base['pid']])->select();
			$this->assign('base',$base);
			$this->assign('workexp',$workexp);
			$this->assign('pexp',$pexp);
			$this->assign('edu',$edu);
			$this->assign('opus',$opus);
			$this->display('user/preview');
		}
}
		


?>